package com.microservice.wechat.controller;

import com.microservice.wechat.scheduler.DraftCountScheduler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 草稿箱统计控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/wechat/draft")
@RequiredArgsConstructor
public class DraftCountController {
    
    private final DraftCountScheduler draftCountScheduler;
    
    /**
     * 手动触发草稿箱统计任务
     * 
     * @return 响应结果
     */
    @PostMapping("/count/trigger")
    public Map<String, Object> triggerDraftCount() {
        log.info("手动触发草稿箱统计任务");
        
        try {
            draftCountScheduler.manualSync();
            
            Map<String, Object> result = new HashMap<>();
            result.put("success", true);
            result.put("message", "草稿箱统计任务已触发，请查看日志或邮箱获取结果");
            return result;
            
        } catch (Exception e) {
            log.error("触发草稿箱统计任务失败", e);
            
            Map<String, Object> result = new HashMap<>();
            result.put("success", false);
            result.put("message", "触发失败: " + e.getMessage());
            return result;
        }
    }
}
